﻿using System;
using System.Xml.Schema;
using System.Xml.Serialization;
using flickr.api.communication;

namespace flickr.api
{
	[Serializable]
	public class Photosets : FlickrObject
	{
	    public Photosets() : base() {}
	    public Photosets(FlickrConnection connection) : base(connection){}
	    
		[XmlAttribute("cancreate", Form=XmlSchemaForm.Unqualified)]
		public int CanCreate;

		[XmlElement("photoset", Form=XmlSchemaForm.Unqualified)]
		public Photoset[] PhotosetCollection;
	    
	    public void addPhoto(string photoSetId, string photoId)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.PhotoSetId, photoSetId);
            request.AddParameter(FlickrParameterType.PhotoId, photoId);

            Send(request);
	    }
	    
	    public Photoset create(string title, string description, string primaryPhotoId)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.PrimaryPhotoId, primaryPhotoId);
            request.AddParameter(FlickrParameterType.Title, title);
            request.AddParameter(FlickrParameterType.Description, description);

            return Send(request).Photoset;
	    }
	    
	    public void delete(string photoSetId)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.PhotoSetId, photoSetId);

            Send(request);
	    }
	    
	    public void editMeta(string photoSetId, string title, string description)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.PhotoSetId, photoSetId);
            request.AddParameter(FlickrParameterType.Title, title);
            request.AddParameter(FlickrParameterType.Description, description);

            Send(request);
	    }
	    
	    public void editPhotos(string photoSetId, string primaryPhotoId, params string[] photoIds)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.PhotoSetId, photoSetId);
            request.AddParameter(FlickrParameterType.PrimaryPhotoId, primaryPhotoId);
            request.AddParameter(FlickrParameterType.PhotoIds, photoIds);

            Send(request);
	    }
	    
//	    public Context getContext(string photoId, string photoSetId)
//	    {
//            FlickrRequest request = CreateRequest();
//            request.AddParameter(FlickrParameterType.PhotoSetId, photoSetId);
//            request.AddParameter(FlickrParameterType.PhotoId, photoId);
//
//            Send(request);
//	    }
	    
	    public Photoset getInfo(string photoSetId)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.PhotoSetId, photoSetId);

            return Send(request).Photoset;
	    }
	    
	    public Photosets getList(string userId)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.UserId, userId);

            return Send(request).Photosets;
	    }
	    
	    public Photoset getPhotos(string photoSetId, PhotoSearchExtras extras, PrivateFilter filter)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.PhotoSetId, photoSetId);
            request.AddParameter(FlickrParameterType.Extras, extras);
            request.AddParameter(FlickrParameterType.PrivacyFilter, filter);

            return Send(request).Photoset;
	    }
	    
	    public void orderSets(params string[] photoSetIds)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.PhotoSetIds, photoSetIds);

            Send(request);
	    }
	    
	    public void removePhoto(string photoSetId, string photoId)
	    {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.PhotoId, photoId);
            request.AddParameter(FlickrParameterType.PhotoSetId, photoSetId);

            Send(request);
	    }
	}
}